#ifndef TEXTURELOADER_H
#define TEXTURELOADER_H

#include <Windows.h>
#include <gl/GL.h>
#include <gl/GLU.h>
#include <SDL.h>

#include <string>
#include <map>
#include <IL/ilut.h>

class TextureLoader
{
	std::map< std::string, unsigned int> m_textures;

public:
	static TextureLoader& getInstance()
	{
		static TextureLoader instance;
		return instance;
	}

	TextureLoader()
	{
		ilInit();  
		iluInit();  
		ilutInit();  
		ilutRenderer(ILUT_OPENGL);  
	}

	~TextureLoader()
	{
		std::map< std::string, unsigned int>::iterator it;
		for( it = m_textures.begin(); it != m_textures.end(); it++ )
		{
			glDeleteTextures(1, (GLuint *) &it->second);
		}
	}

	unsigned int TextureLoader::loadTexture( const std::string& filename )
	{
		std::map< std::string, unsigned int>::iterator it = m_textures.find(filename);
		if( it != m_textures.end() ) 
			return it->second;

		m_textures[filename] = ilutGLLoadImage((char *) filename.c_str());
		printf("Loading texture: %s\n", filename.c_str());
		return m_textures[filename];
	}
};

#endif